package com.wzy.validation;

import java.util.Date;
import java.util.List;

import javax.validation.GroupSequence;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import javax.validation.groups.Default;

import org.hibernate.validator.constraints.Length;

public class UserInfo
{
	// login
	public interface LoginGroup
	{
	}

	// register
	public interface RegisterGroup
	{
	}

	// 组排序场景 , 会按照下面指定的顺序进行校验，没有明确分组的字段，归属于默认组
	@GroupSequence({
			LoginGroup.class,
			RegisterGroup.class,
			Default.class
	})
	public interface Group
	{
	}

	@NotNull(message = "userId must not null", groups = LoginGroup.class)
	private String userId;
	@NotEmpty(message = "userName must not null")
	private String userName;
	@NotBlank(message = "password must not null")
	@Length(min = 6, max = 20, message = "password length must 6 to 12")
	private String password;
	@javax.validation.constraints.Email(message = "email error")
	@NotBlank(message = "邮箱不能为空", groups = RegisterGroup.class)
	private String Email;

	private String phone;
	@Min(value = 0, message = " age must gt 0 ")
	@Max(value = 100, message = "age must lt 100")
	private Integer age;
	@Past(message = "birthday error")
	private Date birthday;
	@Size(min = 0, max = 3, message = "friend list length must 1-3")
	// 级联验证
	private List<@Valid UserInfo> friends;

	public String getUserId()
	{
		return userId;
	}

	public void setUserId(String userId)
	{
		this.userId = userId;
	}

	public String getUserName()
	{
		return userName;
	}

	public void setUserName(String userName)
	{
		this.userName = userName;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getEmail()
	{
		return Email;
	}

	public void setEmail(String email)
	{
		Email = email;
	}

	public String getPhone()
	{
		return phone;
	}

	public void setPhone(String phone)
	{
		this.phone = phone;
	}

	public Date getBirthday()
	{
		return birthday;
	}

	public void setBirthday(Date birthday)
	{
		this.birthday = birthday;
	}

	public List<UserInfo> getFriends()
	{
		return friends;
	}

	public void setFriends(List<UserInfo> friends)
	{
		this.friends = friends;
	}

	public Integer getAge()
	{
		return age;
	}

	public void setAge(Integer age)
	{
		this.age = age;
	}


}

